
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>配置中心-Config · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-sidebar-style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="14.消息总线-bus.html" />
    
    
    <link rel="prev" href="12.网关-Gateway.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">基础篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../java基础/IO流基础.html">
            
                <a href="../java基础/IO流基础.html">
            
                    
                    IO流基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../java基础/集合.html">
            
                <a href="../java基础/集合.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../java基础/异常处理.html">
            
                <a href="../java基础/异常处理.html">
            
                    
                    异常处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../java基础/线程.html">
            
                <a href="../java基础/线程.html">
            
                    
                    线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../java基础/网络编程.html">
            
                <a href="../java基础/网络编程.html">
            
                    
                    网络编程
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../java进阶/MySQL.html">
            
                <a href="../java进阶/MySQL.html">
            
                    
                    MySQL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../java进阶/Oracle.html">
            
                <a href="../java进阶/Oracle.html">
            
                    
                    Oracle
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../java进阶/Redis.html">
            
                <a href="../java进阶/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../java进阶/Netty.html">
            
                <a href="../java进阶/Netty.html">
            
                    
                    Netty
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../java进阶/Spring.html">
            
                <a href="../java进阶/Spring.html">
            
                    
                    Spring
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../java进阶/SpringMVC.html">
            
                <a href="../java进阶/SpringMVC.html">
            
                    
                    SpringMVC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../java进阶/单元测试.html">
            
                <a href="../java进阶/单元测试.html">
            
                    
                    SpringBoot单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="../java进阶/设计模式.html">
            
                <a href="../java进阶/设计模式.html">
            
                    
                    二十三个设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.8.1" data-path="../java进阶/工厂模式.html">
            
                <a href="../java进阶/工厂模式.html">
            
                    
                    工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.2" data-path="../java进阶/单例模式.html">
            
                <a href="../java进阶/单例模式.html">
            
                    
                    单例模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.3" data-path="../java进阶/建造者模式.html">
            
                <a href="../java进阶/建造者模式.html">
            
                    
                    建造者模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.4" data-path="../java进阶/原型模式.html">
            
                <a href="../java进阶/原型模式.html">
            
                    
                    原型模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.5" data-path="../java进阶/适配器模式.html">
            
                <a href="../java进阶/适配器模式.html">
            
                    
                    适配器模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.6" data-path="../java进阶/责任链模式.html">
            
                <a href="../java进阶/责任链模式.html">
            
                    
                    责任链模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.8.7" data-path="../java进阶/桥接模式.html">
            
                <a href="../java进阶/桥接模式.html">
            
                    
                    桥接模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">高级篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="1.cloud架构选型.html">
            
                <a href="1.cloud架构选型.html">
            
                    
                    Spring Cloud
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="2.Provider-支付模块.html">
            
                <a href="2.Provider-支付模块.html">
            
                    
                    Provider-支付模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="3.Consumer-订单模块.html">
            
                <a href="3.Consumer-订单模块.html">
            
                    
                    Consumer-订单模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="4.重构-Common模块.html">
            
                <a href="4.重构-Common模块.html">
            
                    
                    重构-Common模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="5.注册中心-Enreka.html">
            
                <a href="5.注册中心-Enreka.html">
            
                    
                    注册中心-Enreka
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="6.负载均衡-@LoadBalance.html">
            
                <a href="6.负载均衡-@LoadBalance.html">
            
                    
                    负载均衡-@LoadBalance
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="7.更换注册中心-Zookeeper.html">
            
                <a href="7.更换注册中心-Zookeeper.html">
            
                    
                    更换注册中心-Zookeeper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="8.更换注册中心-Consul.html">
            
                <a href="8.更换注册中心-Consul.html">
            
                    
                    更换注册中心-Consul
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="9.负载均衡-Ribbon.html">
            
                <a href="9.负载均衡-Ribbon.html">
            
                    
                    负载均衡-Ribbon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.9" data-path="10.服务调用-OpenFeign.html">
            
                <a href="10.服务调用-OpenFeign.html">
            
                    
                    服务调用-OpenFeign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.10" data-path="11.熔断器-Hystrix.html">
            
                <a href="11.熔断器-Hystrix.html">
            
                    
                    熔断器-Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.11" data-path="12.网关-Gateway.html">
            
                <a href="12.网关-Gateway.html">
            
                    
                    网关-Gateway
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.1.12" data-path="13.配置中心-Config.html">
            
                <a href="13.配置中心-Config.html">
            
                    
                    配置中心-Config
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.13" data-path="14.消息总线-bus.html">
            
                <a href="14.消息总线-bus.html">
            
                    
                    消息总线-Bus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.14" data-path="15.消息驱动-stream.html">
            
                <a href="15.消息驱动-stream.html">
            
                    
                    消息驱动-Stream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.15" data-path="16.链路监控-Sleuth.html">
            
                <a href="16.链路监控-Sleuth.html">
            
                    
                    链路监控-Sleuth
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.16" data-path="17.注册中心&配置中心-nacos.html">
            
                <a href="17.注册中心&配置中心-nacos.html">
            
                    
                    注册中心&配置中心-nacos
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.17" data-path="18.限流-sentinel.html">
            
                <a href="18.限流-sentinel.html">
            
                    
                    限流-sentinel
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../java高级/JUC.html">
            
                <a href="../java高级/JUC.html">
            
                    
                    神秘的JUC包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../java高级/Docker.html">
            
                <a href="../java高级/Docker.html">
            
                    
                    Docker
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../java高级/布隆过滤器.html">
            
                <a href="../java高级/布隆过滤器.html">
            
                    
                    布隆过滤器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../java高级/Redission.html">
            
                <a href="../java高级/Redission.html">
            
                    
                    Redission
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="../java高级/MQ.html">
            
                <a href="../java高级/MQ.html">
            
                    
                    消息队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="../java高级/JVM.html">
            
                <a href="../java高级/JVM.html">
            
                    
                    JVM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="../java书籍/《Effective Java》读书笔记.html">
            
                <a href="../java书籍/《Effective Java》读书笔记.html">
            
                    
                    《Effective Java》读书笔记 
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.8.1" data-path="../java书籍/创建和销毁对象.html">
            
                <a href="../java书籍/创建和销毁对象.html">
            
                    
                    创建和销毁对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">番外篇</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../java面试/面试题.html">
            
                <a href="../java面试/面试题.html">
            
                    
                    面试题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../番外篇/小程序.html">
            
                <a href="../番外篇/小程序.html">
            
                    
                    微信小程序
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >配置中心-Config</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="1&#x6982;&#x8FF0;"><a name="1&#x6982;&#x8FF0;" class="plugin-anchor" href="#1&#x6982;&#x8FF0;"><i class="fa fa-link" aria-hidden="true"></i></a>1.&#x6982;&#x8FF0;</h3>
<p>Spring Cloud Config &#x662F;&#x7531; Spring Cloud &#x56E2;&#x961F;&#x5F00;&#x53D1;&#x7684;&#x9879;&#x76EE;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x4E3A;&#x5FAE;&#x670D;&#x52A1;&#x67B6;&#x6784;&#x4E2D;&#x5404;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x96C6;&#x4E2D;&#x5316;&#x7684;&#x5916;&#x90E8;&#x914D;&#x7F6E;&#x652F;&#x6301;&#x3002;</p>
<p>&#x7B80;&#x5355;&#x70B9;&#x8BF4;&#x5C31;&#x662F;&#xFF0C;Spring Cloud Config &#x53EF;&#x4EE5;&#x5C06;&#x5404;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x96C6;&#x4E2D;&#x5B58;&#x50A8;&#x5728;&#x4E00;&#x4E2A;&#x5916;&#x90E8;&#x7684;&#x5B58;&#x50A8;&#x4ED3;&#x5E93;&#x6216;&#x7CFB;&#x7EDF;&#xFF08;&#x4F8B;&#x5982; Git &#x3001;SVN &#x7B49;&#xFF09;&#x4E2D;&#xFF0C;&#x5BF9;&#x914D;&#x7F6E;&#x7684;&#x7EDF;&#x4E00;&#x7BA1;&#x7406;&#xFF0C;&#x4EE5;&#x652F;&#x6301;&#x5404;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#x7684;&#x8FD0;&#x884C;&#x3002;</p>
<p>Spring Cloud Config &#x5305;&#x542B;&#x4EE5;&#x4E0B;&#x4E24;&#x4E2A;&#x90E8;&#x5206;&#xFF1A;</p>
<ul>
<li>Config Server&#xFF1A;&#x4E5F;&#x88AB;&#x79F0;&#x4E3A;&#x5206;&#x5E03;&#x5F0F;&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x72EC;&#x7ACB;&#x8FD0;&#x884C;&#x7684;&#x5FAE;&#x670D;&#x52A1;&#x5E94;&#x7528;&#xFF0C;&#x7528;&#x6765;&#x8FDE;&#x63A5;&#x914D;&#x7F6E;&#x4ED3;&#x5E93;&#x5E76;&#x4E3A;&#x5BA2;&#x6237;&#x7AEF;&#x63D0;&#x4F9B;&#x83B7;&#x53D6;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#x3001;&#x52A0;&#x5BC6;&#x4FE1;&#x606F;&#x548C;&#x89E3;&#x5BC6;&#x4FE1;&#x606F;&#x7684;&#x8BBF;&#x95EE;&#x63A5;&#x53E3;&#x3002;</li>
<li>Config Client&#xFF1A;&#x6307;&#x7684;&#x662F;&#x5FAE;&#x670D;&#x52A1;&#x67B6;&#x6784;&#x4E2D;&#x7684;&#x5404;&#x4E2A;&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x5B83;&#x4EEC;&#x901A;&#x8FC7; Config Server &#x5BF9;&#x914D;&#x7F6E;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#xFF0C;&#x5E76;&#x4ECE; Config Sever &#x4E2D;&#x83B7;&#x53D6;&#x548C;&#x52A0;&#x8F7D;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#x3002;</li>
</ul>
<p>Spring Cloud Config &#x9ED8;&#x8BA4;&#x4F7F;&#x7528; Git &#x5B58;&#x50A8;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF0C;&#x56E0;&#x6B64;&#x4F7F;&#x7528; Spirng Cloud Config &#x6784;&#x5EFA;&#x7684;&#x914D;&#x7F6E;&#x670D;&#x52A1;&#x5668;&#x5929;&#x7136;&#x5C31;&#x652F;&#x6301;&#x5BF9;&#x5FAE;&#x670D;&#x52A1;&#x914D;&#x7F6E;&#x7684;&#x7248;&#x672C;&#x7BA1;&#x7406;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; Git &#x5BA2;&#x6237;&#x7AEF;&#x5DE5;&#x5177;&#x65B9;&#x4FBF;&#x5730;&#x5BF9;&#x914D;&#x7F6E;&#x5185;&#x5BB9;&#x8FDB;&#x884C;&#x7BA1;&#x7406;&#x548C;&#x8BBF;&#x95EE;&#x3002;&#x9664;&#x4E86; Git &#x5916;&#xFF0C;Spring Cloud Config &#x8FD8;&#x63D0;&#x4F9B;&#x4E86;&#x5BF9;&#x5176;&#x4ED6;&#x5B58;&#x50A8;&#x65B9;&#x5F0F;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x4F8B;&#x5982; SVN&#x3001;&#x672C;&#x5730;&#x5316;&#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x7B49;&#x3002;</p>
<p><img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h3x08y7nq6j20y40hkt9f.jpg" alt="&#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;"></p>
<p>Spring Cloud Config &#x5DE5;&#x4F5C;&#x6D41;&#x7A0B;&#x5982;&#x4E0B;&#xFF1A;</p>
<ol>
<li>&#x5F00;&#x53D1;&#x6216;&#x8FD0;&#x7EF4;&#x4EBA;&#x5458;&#x63D0;&#x4EA4;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5230;&#x8FDC;&#x7A0B;&#x7684; Git &#x4ED3;&#x5E93;&#x3002;</li>
<li>Config &#x670D;&#x52A1;&#x7AEF;&#xFF08;&#x5206;&#x5E03;&#x5F0F;&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;&#xFF09;&#x8D1F;&#x8D23;&#x8FDE;&#x63A5;&#x914D;&#x7F6E;&#x4ED3;&#x5E93; Git&#xFF0C;&#x5E76;&#x5BF9; Config &#x5BA2;&#x6237;&#x7AEF;&#x66B4;&#x9732;&#x83B7;&#x53D6;&#x914D;&#x7F6E;&#x7684;&#x63A5;&#x53E3;&#x3002;</li>
<li>Config &#x5BA2;&#x6237;&#x7AEF;&#x901A;&#x8FC7; Config &#x670D;&#x52A1;&#x7AEF;&#x66B4;&#x9732;&#x51FA;&#x6765;&#x7684;&#x63A5;&#x53E3;&#xFF0C;&#x62C9;&#x53D6;&#x914D;&#x7F6E;&#x4ED3;&#x5E93;&#x4E2D;&#x7684;&#x914D;&#x7F6E;&#x3002;</li>
<li>Config &#x5BA2;&#x6237;&#x7AEF;&#x83B7;&#x53D6;&#x5230;&#x914D;&#x7F6E;&#x4FE1;&#x606F;&#xFF0C;&#x4EE5;&#x652F;&#x6301;&#x670D;&#x52A1;&#x7684;&#x8FD0;&#x884C;&#x3002;</li>
</ol>
<h3 id="2-&#x521B;&#x5EFA;&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;server&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x8BFB;&#x53D6;git&#x4E0A;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><a name="2-&#x521B;&#x5EFA;&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;server&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x8BFB;&#x53D6;git&#x4E0A;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;" class="plugin-anchor" href="#2-&#x521B;&#x5EFA;&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;server&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x8BFB;&#x53D6;git&#x4E0A;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x521B;&#x5EFA;&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;server&#x5FAE;&#x670D;&#x52A1;&#xFF0C;&#x8BFB;&#x53D6;git&#x4E0A;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;</h3>
<p>pom.xml</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">project</span> <span class="hljs-attr">xmlns</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0&quot;</span>
         <span class="hljs-attr">xmlns:xsi</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span>
         <span class="hljs-attr">xsi:schemaLocation</span>=<span class="hljs-string">&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">parent</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>bigdata<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>com.springcloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>1.0-SNAPSHOT<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">parent</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">modelVersion</span>&gt;</span>4.0.0<span class="hljs-tag">&lt;/<span class="hljs-name">modelVersion</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>cloud-config<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">dependencies</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-config-server<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-comment">&lt;!--eureka--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-netflix-eureka-client<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-comment">&lt;!--web--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-actuator<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-comment">&lt;!--&#x70ED;&#x90E8;&#x7F72;--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-devtools<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>runtime<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">optional</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">optional</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>

        <span class="hljs-comment">&lt;!--test--&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">dependencies</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">project</span>&gt;</span>
</code></pre>
<p>application.yml</p>
<pre><code class="lang-yml"><span class="hljs-attr">server:</span>
<span class="hljs-attr">  port:</span> <span class="hljs-number">3344</span>

<span class="hljs-attr">spring:</span>
<span class="hljs-attr">  application:</span>
<span class="hljs-attr">    name:</span> cloud-config
<span class="hljs-attr">  cloud:</span>
<span class="hljs-attr">    config:</span>
<span class="hljs-attr">      server:</span>
<span class="hljs-attr">        git:</span>
<span class="hljs-attr">          uri:</span> https://gitee.com/liang-xinglong/cloud-config.git
<span class="hljs-attr">          search-paths:</span> cloud-config
          <span class="hljs-comment"># &#x6CA1;&#x6709;&#x914D;&#x7F6E;&#x53EF;&#x80FD;&#x542F;&#x52A8;&#x629B;&#x51FA; Authentication is required but no CredentialsProvider has been registered.</span>
<span class="hljs-attr">          username:</span> liang-xinglong
<span class="hljs-attr">          password:</span> *****
<span class="hljs-attr">        label:</span> master

<span class="hljs-attr">eureka:</span>
<span class="hljs-attr">  instance:</span>
<span class="hljs-attr">    hostname:</span> cloud-config-service
<span class="hljs-attr">  client:</span>
<span class="hljs-attr">    register-with-eureka:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    fetch-registry:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    service-url:</span>
<span class="hljs-attr">      defaultZone:</span> http://localhost:<span class="hljs-number">7001</span>/eureka/
</code></pre>
<p>&#x542F;&#x52A8;&#x7C7B;</p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> org.springframework.boot.SpringApplication;
<span class="hljs-keyword">import</span> org.springframework.boot.autoconfigure.SpringBootApplication;
<span class="hljs-keyword">import</span> org.springframework.cloud.config.server.EnableConfigServer;

<span class="hljs-meta">@SpringBootApplication</span>
<span class="hljs-meta">@EnableConfigServer</span>
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CloudConfigApplication</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        SpringApplication.run(CloudConfigApplication.class,args);
    }
}
</code></pre>
<h3 id="3&#x51C6;&#x5907;&#x914D;&#x7F6E;&#x4ED3;&#x5E93;"><a name="3&#x51C6;&#x5907;&#x914D;&#x7F6E;&#x4ED3;&#x5E93;" class="plugin-anchor" href="#3&#x51C6;&#x5907;&#x914D;&#x7F6E;&#x4ED3;&#x5E93;"><i class="fa fa-link" aria-hidden="true"></i></a>3.&#x51C6;&#x5907;&#x914D;&#x7F6E;&#x4ED3;&#x5E93;</h3>
<p>&#x5728;gitee&#x6216;&#x8005;github&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x9879;&#x76EE;&#xFF0C;&#x65B0;&#x5EFA;&#x6587;&#x4EF6;</p>
<p><img src="https://tva1.sinaimg.cn/large/e6c9d24ely1h3x79nfu0tj20a804mgln.jpg" alt=""></p>
<p>&#x6BCF;&#x4E2A;&#x968F;&#x4FBF;&#x5199;&#x70B9;&#x4E1C;&#x897F;</p>
<pre><code class="lang-yml"><span class="hljs-attr">config:</span>
<span class="hljs-attr">  info:</span> this is master brach , dev env file
</code></pre>
<p>&#x8BBF;&#x95EE;&#x89C4;&#x5219;:</p>
<pre><code class="lang-yml"><span class="hljs-comment"># label:  &#x5206;&#x652F; branch</span>
<span class="hljs-comment"># name: &#x670D;&#x52A1;&#x540D;</span>
<span class="hljs-comment"># prifiles: &#x73AF;&#x5883;</span>

/{label}/{name}-{profile}.yml   <span class="hljs-comment"># http://localhost:3344/master/application-dev.yml</span>
/{name}-{profile}.yml           <span class="hljs-comment"># http://localhost:3344/application-dev.yml</span>
/{name}/{profile}/{label}       <span class="hljs-comment"># http://localhost:3344/application/dev/master</span>
</code></pre>
<h3 id="4&#x642D;&#x5EFA;&#x5BA2;&#x6237;&#x7AEF;&#x8BFB;&#x53D6;config-server&#x7AEF;&#x7684;&#x6570;&#x636E;"><a name="4&#x642D;&#x5EFA;&#x5BA2;&#x6237;&#x7AEF;&#x8BFB;&#x53D6;config-server&#x7AEF;&#x7684;&#x6570;&#x636E;" class="plugin-anchor" href="#4&#x642D;&#x5EFA;&#x5BA2;&#x6237;&#x7AEF;&#x8BFB;&#x53D6;config-server&#x7AEF;&#x7684;&#x6570;&#x636E;"><i class="fa fa-link" aria-hidden="true"></i></a>4.&#x642D;&#x5EFA;&#x5BA2;&#x6237;&#x7AEF;&#x8BFB;&#x53D6;config server&#x7AEF;&#x7684;&#x6570;&#x636E;</h3>
<p>&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#xFF0C;&#x5176;&#x6B21;&#x4E5F;&#x4E3A;&#x4E86;&#x8FD8;&#x539F;&#x9879;&#x76EE;&#x5E94;&#x7528;&#xFF0C;&#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x8BA2;&#x5355;&#x6A21;&#x5757;</p>
<p>&#x65B0;&#x589E;bootstrap.yml</p>
<pre><code class="lang-yml"><span class="hljs-attr">server:</span>
<span class="hljs-attr">  port:</span> <span class="hljs-number">80</span>

<span class="hljs-attr">eureka:</span>
<span class="hljs-attr">  client:</span>
<span class="hljs-attr">    register-with-eureka:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    fetch-registry:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    service-url:</span>
<span class="hljs-attr">      defaultZone:</span> http://localhost:<span class="hljs-number">7001</span>/eureka/
<span class="hljs-attr">spring:</span>
<span class="hljs-attr">  application:</span>
<span class="hljs-attr">    name:</span> eureka-consumer-order
<span class="hljs-attr">  cloud:</span>
<span class="hljs-attr">    config:</span>
<span class="hljs-attr">      label:</span> master
<span class="hljs-attr">      name:</span> application
<span class="hljs-attr">      profile:</span> dev
<span class="hljs-attr">      uri:</span> http://localhost:<span class="hljs-number">3344</span>
</code></pre>
<p>&#x4FEE;&#x6539;application.yml (&#x5176;&#x5B9E;&#x5C31;&#x662F;&#x628A;&#x4E00;&#x90E8;&#x5206;&#x79FB;&#x5230;&#x4E86;bootstrap.yml)</p>
<pre><code class="lang-yml"><span class="hljs-comment"># &#x8BBE;&#x7F6E;feign &#x5BA2;&#x6237;&#x7AEF;&#x8D85;&#x65F6;&#x65F6;&#x95F4;(OpenFeign&#x9ED8;&#x8BA4;&#x652F;&#x6301;ribbon)</span>
<span class="hljs-attr">ribbon:</span>
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x540E;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x8BFB;&#x53D6;&#x5230;&#x53EF;&#x7528;&#x8D44;&#x6E90;&#x6240;&#x7528;&#x7684;&#x65F6;&#x95F4;</span>
<span class="hljs-attr">  ReadTimeout:</span> <span class="hljs-number">5000</span>
  <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x5EFA;&#x7ACB;&#x8FDE;&#x63A5;&#x6240;&#x7528;&#x7684;&#x65F6;&#x95F4;,&#x9002;&#x7528;&#x4E8E;&#x7F51;&#x7EDC;&#x72B6;&#x51B5;&#x6B63;&#x5E38;&#x7684;&#x60C5;&#x51B5;&#x4E0B;,&#x4E24;&#x7AEF;&#x8FDE;&#x63A5;&#x6240;&#x7528;&#x7684;&#x65F6;&#x95F4;</span>
<span class="hljs-attr">  ConnectTimeout:</span> <span class="hljs-number">5000</span>

<span class="hljs-attr">logging:</span>
<span class="hljs-attr">  level:</span>
    <span class="hljs-comment"># feign &#x65E5;&#x5FD7;&#x4EE5;&#x4EC0;&#x4E48;&#x7EA7;&#x522B;&#x76D1;&#x63A7;&#x54EA;&#x4E2A;&#x63A5;&#x53E3;</span>
    com.springcloud.service.IRemotePaymentService: debug

<span class="hljs-comment"># &#x5F00;&#x542F;feign&#x8C03;&#x7528;</span>
<span class="hljs-attr">feign:</span>
<span class="hljs-attr">  hystrix:</span>
<span class="hljs-attr">    enabled:</span> <span class="hljs-literal">true</span>

<span class="hljs-comment"># &#x89E3;&#x8026;&#x964D;&#x7EA7;&#x7684;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x914D;&#x7F6E;</span>
<span class="hljs-attr">hystrix:</span>
<span class="hljs-attr">  command:</span>
<span class="hljs-attr">    default:</span>
<span class="hljs-attr">      execution:</span>
<span class="hljs-attr">        isolation:</span>
<span class="hljs-attr">          thread:</span>
<span class="hljs-attr">            timeoutInMilliseconds:</span> <span class="hljs-number">3000</span>
</code></pre>
<p>pom.xml &#x65B0;&#x589E;&#x5982;&#x4E0B;&#x4F9D;&#x8D56;</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!--config client--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.cloud<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-cloud-starter-config<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<p>controller</p>
<pre><code class="lang-java"><span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${config.info}&quot;</span>)
<span class="hljs-keyword">private</span> String info;

<span class="hljs-comment">//&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;</span>
<span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getConfig&quot;</span>)
<span class="hljs-meta">@HystrixCommand</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getConfig</span><span class="hljs-params">()</span></span>{
   <span class="hljs-keyword">return</span> info;
}
</code></pre>
<h3 id="5-&#x52A8;&#x6001;&#x5237;&#x65B0;"><a name="5-&#x52A8;&#x6001;&#x5237;&#x65B0;" class="plugin-anchor" href="#5-&#x52A8;&#x6001;&#x5237;&#x65B0;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x52A8;&#x6001;&#x5237;&#x65B0;</h3>
<p>&#x5F53;&#x9879;&#x76EE;&#x5168;&#x90E8;&#x542F;&#x52A8;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x4FEE;&#x6539;git&#x4E0A;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;</p>
<p>&#x7136;&#x540E;&#x8BBF;&#x95EE;3344&#x7AEF;&#x53E3;&#x9879;&#x76EE; &#x4E5F;&#x5C31;&#x662F;config server&#x7AEF;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x62FF;&#x5230;&#x65B0;&#x7248;&#x4FEE;&#x6539;&#x540E;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;</p>
<p>&#x7136;&#x540E;&#x8BBF;&#x95EE;3355&#x7AEF;&#x53E3;&#x9879;&#x76EE; &#x4E5F;&#x5C31;&#x662F;config client&#x7AEF;&#xFF0C;&#x53D1;&#x73B0;&#x8FD4;&#x56DE;&#x7684;&#x8FD8;&#x662F;&#x65E7;&#x7248;&#x672C;&#x7684;&#x914D;&#x7F6E;&#x4FE1;&#x606F;</p>
<p>&#x4FEE;&#x6539;controller&#xFF0C;&#x5728;&#x7C7B;&#x4E0A;&#x6DFB;&#x52A0; @RefreshScope &#x6CE8;&#x89E3;</p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> cn.hutool.core.util.IdUtil;
<span class="hljs-keyword">import</span> com.springcloud.base.CommonResult;
<span class="hljs-keyword">import</span> com.springcloud.entities.Payment;
<span class="hljs-keyword">import</span> com.springcloud.service.IRemotePaymentService;
<span class="hljs-keyword">import</span> com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
<span class="hljs-keyword">import</span> com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
<span class="hljs-keyword">import</span> com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
<span class="hljs-keyword">import</span> lombok.extern.slf4j.Slf4j;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Autowired;
<span class="hljs-keyword">import</span> org.springframework.beans.factory.annotation.Value;
<span class="hljs-keyword">import</span> org.springframework.cloud.context.config.annotation.RefreshScope;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.GetMapping;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.PathVariable;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RequestMapping;
<span class="hljs-keyword">import</span> org.springframework.web.bind.annotation.RestController;

<span class="hljs-meta">@RestController</span>
<span class="hljs-meta">@RequestMapping</span>(<span class="hljs-string">&quot;/order&quot;</span>)
<span class="hljs-meta">@Slf</span>4j
<span class="hljs-meta">@RefreshScope</span> 
<span class="hljs-meta">@DefaultProperties</span>(defaultFallback = <span class="hljs-string">&quot;testHystrixGlobalFallback&quot;</span>)
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">OrderController</span> </span>{

    <span class="hljs-meta">@Value</span>(<span class="hljs-string">&quot;${config.info}&quot;</span>)
    <span class="hljs-keyword">private</span> String info;

    <span class="hljs-meta">@Autowired</span>
    <span class="hljs-keyword">private</span> IRemotePaymentService remotePaymentService;

    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getPaymentById/{id}&quot;</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">get</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id)</span>{
        CommonResult&lt;Payment&gt; paymentById = remotePaymentService.getPayment(id);
        <span class="hljs-keyword">return</span> paymentById;
    }


    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getString&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">get</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">int</span> i = <span class="hljs-number">1</span>/<span class="hljs-number">0</span>;
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&quot;</span>;
    }

    <span class="hljs-comment">// &#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF01;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> CommonResult&lt;Payment&gt; <span class="hljs-title">testHystrixTimoutFallback</span><span class="hljs-params">(Long id)</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
         log.info(id + <span class="hljs-string">&quot;&#x964D;&#x7EA7;&#x670D;&#x52A1;&#x65B9;&#x6CD5;&#x6267;&#x884C;!&quot;</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
    }

    <span class="hljs-comment">// &#x5168;&#x5C40;&#x515C;&#x5E95;&#x65B9;&#x6CD5;&#xFF01;</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">testHystrixGlobalFallback</span><span class="hljs-params">()</span> <span class="hljs-keyword">throws</span> InterruptedException </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x5168;&#x5C40;&#x7684;&#x964D;&#x7EA7;&#x670D;&#x52A1;&#x65B9;&#x6CD5;&#x6267;&#x884C;!&quot;</span>;

    }

    <span class="hljs-comment">//&#x7194;&#x65AD;</span>
    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/circuit/getPaymentById/{id}&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span>(fallbackMethod = <span class="hljs-string">&quot;circuitBreakerFallback&quot;</span>,commandProperties = {
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.enabled&quot;</span>,value = <span class="hljs-string">&quot;true&quot;</span>),
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.requestVolumeThreshold&quot;</span>,value = <span class="hljs-string">&quot;10&quot;</span>),<span class="hljs-comment">//&#x8BF7;&#x6C42;&#x6B21;&#x6570;</span>
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.sleepWindowInMilliseconds&quot;</span>,value = <span class="hljs-string">&quot;10000&quot;</span>),<span class="hljs-comment">//&#x65F6;&#x95F4;&#x7A97;&#x53E3;&#x671F;</span>
            <span class="hljs-meta">@HystrixProperty</span>(name = <span class="hljs-string">&quot;circuitBreaker.errorThresholdPercentage&quot;</span>,value = <span class="hljs-string">&quot;60&quot;</span>)<span class="hljs-comment">//&#x5931;&#x8D25;&#x767E;&#x5206;&#x6BD4;</span>
    })
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getCircuitBreaker</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id) <span class="hljs-keyword">throws</span> Exception</span>{

        <span class="hljs-keyword">if</span>(id&lt;<span class="hljs-number">0</span>){
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Exception(<span class="hljs-string">&quot;id&#x4E0D;&#x80FD;&#x4E3A;&#x8D1F;&#x6570;!&quot;</span>);
        }
        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x8C03;&#x7528;&#x6210;&#x529F;&#x6D41;&#x6C34;&#x53F7;&quot;</span>+ IdUtil.simpleUUID();
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">circuitBreakerFallback</span><span class="hljs-params">(@PathVariable(<span class="hljs-string">&quot;id&quot;</span>)</span> Long id)</span>{

        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;id &#x4E0D;&#x80FD;&#x4E3A;&#x8D1F;&#x6570;&#xFF0C;&#x8BF7;&#x7A0D;&#x540E;&#x518D;&#x8BD5; =&gt; &quot;</span>+id;
    }

    <span class="hljs-comment">//&#x914D;&#x7F6E;&#x4E2D;&#x5FC3;</span>
    <span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/getConfig&quot;</span>)
    <span class="hljs-meta">@HystrixCommand</span>
    <span class="hljs-function"><span class="hljs-keyword">public</span> String <span class="hljs-title">getConfig</span><span class="hljs-params">()</span></span>{
        <span class="hljs-keyword">return</span> info;
    }

}
</code></pre>
<p>bootstrap.yml &#x6DFB;&#x52A0;&#x76D1;&#x63A7;</p>
<pre><code class="lang-yml"><span class="hljs-attr">server:</span>
<span class="hljs-attr">  port:</span> <span class="hljs-number">80</span>

<span class="hljs-attr">eureka:</span>
<span class="hljs-attr">  client:</span>
<span class="hljs-attr">    register-with-eureka:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    fetch-registry:</span> <span class="hljs-literal">true</span>
<span class="hljs-attr">    service-url:</span>
<span class="hljs-attr">      defaultZone:</span> http://localhost:<span class="hljs-number">7001</span>/eureka/
<span class="hljs-attr">spring:</span>
<span class="hljs-attr">  application:</span>
<span class="hljs-attr">    name:</span> eureka-consumer-order
<span class="hljs-attr">  cloud:</span>
<span class="hljs-attr">    config:</span>
<span class="hljs-attr">      label:</span> master
<span class="hljs-attr">      name:</span> application
<span class="hljs-attr">      profile:</span> dev
<span class="hljs-attr">      uri:</span> http://localhost:<span class="hljs-number">3344</span>

<span class="hljs-comment"># &#x66B4;&#x9732;&#x76D1;&#x63A7;&#x7AEF;&#x70B9;</span>
<span class="hljs-attr">management:</span>
<span class="hljs-attr">  endpoints:</span>
<span class="hljs-attr">    web:</span>
<span class="hljs-attr">      exposure:</span>
<span class="hljs-attr">        include:</span> <span class="hljs-string">&quot;*&quot;</span>
</code></pre>
<p>&#x7136;&#x540E;&#x4FEE;&#x6539;&#x4E86;&#x8FDC;&#x7A0B;git&#x4E0A;&#x7684;&#x914D;&#x7F6E;&#x9700;&#x8981;&#x8FD0;&#x7EF4;&#x6267;&#x884C;&#x5982;&#x4E0B;&#x547D;&#x4EE4;&#x8FDB;&#x884C;&#x63A8;&#x9001;&#x5237;&#x65B0;</p>
<pre><code class="lang-shell">curl -X POST &quot;http://localhost:80/actuator/refresh&quot;
</code></pre>
<p> &#x95EE;&#x9898;&#x662F;&#xFF0C;&#x4FEE;&#x6539;&#x4E00;&#x4E2A;&#x670D;&#x52A1;&#x7684;&#x914D;&#x7F6E;&#x8FD8;&#x597D; &#xFF0C;&#x5982;&#x679C;10&#x51E0;&#x4E2A;&#x5462;&#xFF0C;&#x8FD0;&#x7EF4;&#x4E0D;&#x5E72;&#x4E86;&#xFF0C;&#x6240;&#x4EE5;&#x5C31;&#x9700;&#x8981;&#x4E0B;&#x4E00;&#x8282;&#x7684; &#x6D88;&#x606F;&#x603B;&#x7EBF;&#x3002;</p>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; mine 2022-2025 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2022-07-12 10:58:40
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="12.网关-Gateway.html" class="navigation navigation-prev " aria-label="Previous page: 网关-Gateway">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="14.消息总线-bus.html" class="navigation navigation-next " aria-label="Next page: 消息总线-Bus">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"配置中心-Config","level":"4.1.12","depth":2,"next":{"title":"消息总线-Bus","level":"4.1.13","depth":2,"path":"springcloud/14.消息总线-bus.md","ref":"springcloud/14.消息总线-bus.md","articles":[]},"previous":{"title":"网关-Gateway","level":"4.1.11","depth":2,"path":"springcloud/12.网关-Gateway.md","ref":"springcloud/12.网关-Gateway.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["back-to-top-button","code","splitter","expandable-chapters-small","anchors","theme-comscore","tbfed-pagefooter","sidebar-style","pageview-count","popup"],"pluginsConfig":{"sidebar-style":{"author":"梁兴龙","title":"《Java 笔记本》"},"tbfed-pagefooter":{"copyright":"Copyright &copy mine 2022-2025","modify_label":"文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"back-to-top-button":{},"pageview-count":{},"expandable-chapters-small":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"springcloud/13.配置中心-Config.md","mtime":"2022-07-12T02:58:40.532Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-08-22T03:22:22.085Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sidebar-style/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

